package com.pacifictextiles.qc.inspection.server.model.test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pacifictextiles.qc.inspection.server.model.dao.impl.DefectDAOImpl;
import com.pacifictextiles.qc.inspection.server.model.vo.Defect;

/**
 * Servlet implementation class AddDefect
 */
public class AddDefect extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddDefect() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 设置数据编码
		response.setContentType("text/html; charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		
		// 获取参数
		Defect defect = new Defect();
		defect.setIndexInRoll(Integer.parseInt(request.getParameter("indexInRoll")));
		defect.setDefectCode(Integer.parseInt(request.getParameter("defectCode")));
		defect.setPoint(Integer.parseInt(request.getParameter("point")));
		defect.setPosition(Float.parseFloat(request.getParameter("position")));
		defect.setRating(request.getParameter("rating").charAt(0));
		defect.setRollNo(request.getParameter("rollNo"));
		
		// 执行数据库操作
		DefectDAOImpl ddi = new DefectDAOImpl();
		try {
			if (ddi.addDefect(defect)) {
				System.out.println("Insert defect success!");
			} else {
				System.out.println("cao! 老子又进不去！");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
